home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / idcmp.lzh / IDCMP / Example1.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  5KB  |  170 lines

  1. /* Example1                                             */
  2. /* This example shows how to handle MOUSEBUTTONS event. */
  3.  
  4.  
  5.  
  6. #include <intuition/intuition.h>
  7.  
  8.  
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11.  
  12.  
  13.  
  14. /* Declare a pointer to a Window structure: */ 
  15. struct Window *my_window;
  16.  
  17. /* Declare and initialize your NewWindow structure: */
  18. struct NewWindow my_new_window=
  19. {
  20.   50,            /* LeftEdge    x position of the window. */
  21.   25,            /* TopEdge     y positio of the window. */
  22.   320,           /* Width       320 pixels wide. */
  23.   100,           /* Height      100 lines high. */
  24.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  25.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  26.   CLOSEWINDOW|   /* IDCMPFlags  We will recieve a message when the user:  */
  27.                  /*             selects the Close window gad, or when the */
  28.   MOUSEBUTTONS,  /*             user presses/releases the mouse buttons.  */
  29.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  30.   WINDOWCLOSE|   /*             Close Gadget. */
  31.   WINDOWDRAG|    /*             Drag gadget. */
  32.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  33.   WINDOWSIZING|  /*             Sizing Gadget. */
  34.   ACTIVATE|      /*             The window should be Active when opened. */
  35.   
  36.   RMBTRAP,       /*             We do not want any menu operations for   */
  37.                  /*             this window. We can then recieve         */
  38.                  /*             MOUSEBUTTONS events even if the right    */
  39.                  /*             mouse button is pressed. (Such event are */
  40.                  /*             normally swollowed by Intuition.)        */
  41.  
  42.   NULL,          /* FirstGadget No gadgets connected to this window. */
  43.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  44.   "PRESS THE BUTTONS", /* Title Title of the window. */
  45.   NULL,          /* Screen      Connected to the Workbench Screen. */
  46.   NULL,          /* BitMap      No Custom BitMap. */
  47.   100,           /* MinWidth    We will not allow the window to become */
  48.   50,            /* MinHeight   smaller than 100 x 50, and not bigger */
  49.   400,           /* MaxWidth    than 400 x 200. */
  50.   200,           /* MaxHeight */
  51.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  52. };
  53.  
  54.  
  55.  
  56. main()
  57. {
  58.   /* Boolean variable used for the while loop: */
  59.   BOOL close_me;
  60.  
  61.   ULONG class; /* IDCMP flag. */
  62.  
  63.   USHORT code; /* Code. */
  64.   
  65.   /* Pointer to an IntuiMessage structure: */
  66.   struct IntuiMessage *my_message;
  67.  
  68.  
  69.  
  70.   /* Before we can use Intuition we need to open the Intuition Library: */
  71.   IntuitionBase = (struct IntuitionBase *)
  72.     OpenLibrary( "intuition.library", 0 );
  73.   
  74.   if( IntuitionBase == NULL )
  75.     exit(); /* Could NOT open the Intuition Library! */
  76.  
  77.  
  78.  
  79.   /* We will now try to open the window: */
  80.   my_window = (struct Window *) OpenWindow( &my_new_window );
  81.   
  82.   /* Have we opened the window succesfully? */
  83.   if(my_window == NULL)
  84.   {
  85.     /* Could NOT open the Window! */
  86.     
  87.     /* Close the Intuition Library since we have opened it: */
  88.     CloseLibrary( IntuitionBase );
  89.  
  90.     exit();  
  91.   }
  92.  
  93.  
  94.  
  95.   /* We have opened the window, and everything seems to be OK. */
  96.  
  97.   printf("Press the mouse buttons!\n");
  98.  
  99.  
  100.  
  101.   close_me = FALSE;
  102.  
  103.   /* Stay in the while loop until the user has selected the Close window */
  104.   /* gadget: */
  105.   while( close_me == FALSE )
  106.   {
  107.     /* Wait until we have recieved a message: */
  108.     Wait( 1 << my_window->UserPort->mp_SigBit );
  109.  
  110.     /* As long as we can collect messages successfully we stay in the */
  111.     /* while-loop: */
  112.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  113.     {
  114.       /* After we have successfully collected the message we can read */
  115.       /* it, and save any important values which we maybe want to check */
  116.       /* later: */
  117.       class = my_message->Class;
  118.       code  = my_message->Code;
  119.  
  120.       /* After we have read it we reply as fast as possible: */
  121.       /* REMEMBER! Do never try to read a message after you have replied! */
  122.       /* (Some other process has maybe changed it.) */
  123.       ReplyMsg( my_message );
  124.  
  125.       /* Check which IDCMP flag was sent: */
  126.       switch( class )
  127.       {
  128.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  129.                close_me=TRUE;
  130.                break;
  131.         
  132.         case MOUSEBUTTONS: /* The user pressed/released a mouse button. */
  133.                /* We shall now check wich button, and if it was pressed */
  134.                /* or released: */
  135.                switch( code )
  136.                {
  137.                  case SELECTDOWN: /* Left button pressed. */
  138.                         printf("Left mouse button pressed.\n");
  139.                         break;
  140.                  case SELECTUP:   /* Left button releassed. */
  141.                         printf("Left mouse button released.\n");
  142.                         break;
  143.                  case MENUDOWN:   /* Right button pressed. */
  144.                         printf("Right mouse button pressed.\n");
  145.                         break;
  146.                  case MENUUP:     /* Right button released. */
  147.                         printf("Right mouse button released.\n");
  148.                         break;
  149.                }
  150.                break;
  151.       }
  152.     }
  153.   }
  154.  
  155.  
  156.  
  157.   /* Close the window: */
  158.   CloseWindow( my_window );
  159.  
  160.  
  161.  
  162.   /* Close the Intuition Library: */
  163.   CloseLibrary( IntuitionBase );
  164.   
  165.   /* THE END */
  166. }
  167.  
  168.  
  169.  
  170.